package com.eshop.storm.enums;

import lombok.Getter;

/**
 * @author: Xukai
 * @description: Zookeeper分布式锁节点枚举
 * @createDate: 2018/8/3 14:10
 * @modified By:
 */
@Getter
public enum ZkLock {

    TASK_ID_LIST_LOCK("taskIdListLock", "/task-id-list-lock"),
    TASK_ID_LIST("taskIdList", "/task-id-list"),
    TASK_HOT_PRODUCT("taskHotProduct", "/task-hot-product-"),
    /**
     * 保存task处理结果的预热状态，空值表示尚未预热，success表示已经预热
     */
    TASK_ID_STATUS("taskIdStatus", "/task-id-status-"),
    PRODUCT_LOCK("product", "/product-lock-"),
    SHOP_LOCK("shop", "/shop-lock-");

    private String type;

    private String node;

    ZkLock(String type, String node) {
        this.type = type;
        this.node = node;
    }

    public static String getNodeByType(String type) {
        for (ZkLock each : ZkLock.class.getEnumConstants()) {
            if (type.equals(each.getType())) {
                return each.getNode();
            }
        }
        return null;
    }
}
